/*
 * @Description:
 * @version:
 * @Author: sunqian_sr
 * @Date: 2022-11-29 11:08:39
 * @LastEditors: Andy
 * @LastEditTime: 2023-01-30 09:31:32
 */
/**
 * v-hasPermi 操作权限处理
 * Copyright (c) 2019 ruoyi
 */

import { pinias } from '@/common/pinia'

const { login } = pinias
const userLogin = login()

export default {
  inserted(el, binding) {
    const { value } = binding
    const allPermission = '*:*:*'
    const permissions = userLogin.permissionsActions
    if (value && value instanceof Array && value.length > 0) {
      const permissionFlag = value

      const hasPermissions = permissions.some((permission) => {
        return allPermission === permission || permissionFlag.includes(permission)
      })

      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error('请设置操作权限标签值')
    }
  }
}
